import request from '@/utils/request'

// 获取医生排班列表
export function fetchScheduleList(query) {
  return request({
    url: '/system/schedule/list',
    method: 'get',
    params: {
      pageNum: query.pageNum,
      pageSize: query.pageSize,
      departmentId: query.departmentId,
      patientName: query.patientName,
      weekStart: query.weekStart,
      weekEnd: query.weekEnd
    }
  })
}

// 获取医生排班详情
export function getDoctorScheduleDetail(doctorId, date, period) {
  return request({
    url: '/system/schedule/detail',
    method: 'get',
    params: {
      doctorId,
      date,
      period: period === '上午' ? 1 : period === '下午' ? 2 : period
    }
  })
}

// 设置医生排班
export function setDoctorSchedule(data) {
  return request({
    url: '/system/schedule',
    method: 'post',
    data: {
      doctorId: data.doctorId,
      departmentId: data.departmentId,
      scheduleDate: data.scheduleDate,
      period: data.period,
      totalNum: data.totalNum,
      availableNum: data.availableNum,
      startTime: data.startTime,
      endTime: data.endTime,
      scheduleType: data.scheduleType,
      registrationFee: data.registrationFee,
      remark: data.remark
    }
  })
}

// 更新医生排班
export function updateSchedule(data) {
  return request({
    url: '/system/schedule',
    method: 'put',
    data: data
  })
}

// 删除医生排班
export function deleteSchedule(id) {
  return request({
    url: `/system/schedule/${id}`,
    method: 'delete'
  })
}

// 获取医生排班信息
export function getSchedule(id) {
  return request({
    url: `/system/schedule/${id}`,
    method: 'get'
  })
}

// 关闭医生排班
export function closeSchedule(doctorId) {
  return request({
    url: `/system/schedule/close/${doctorId}`,
    method: 'put'
  })
}

// 获取科室列表
export function getParentDepartmentList() {
  return request({
    url: '/system/schedule/department/list',
    method: 'get'
  })
}